{% extends 'base.html' %}
{% load checkboxes %}

{% block title_suffix %}
    | Create user
{% endblock %}

{% block all_content %}
{% if edit_user %}
	<div class="page-header">
		<h1>Edit user <small></small></h1>
	</div>
{% else %}
	<div class="page-header">
		<h1>Create user <small></small></h1>
	</div>
{% endif %}
	
<form class="form-horizontal" action=
{% if edit_user %}
			"/auth/edit/{{ edit_user.id }}/"
{% else %}
			"/auth/create-user/"
{% endif %}

 method="post">
	{% csrf_token %}
	


<div class="tabbable tabs-left"> <!-- Only required for left/right tabs -->
  <ul class="nav nav-tabs">
    <li class="active"><a href="#tab1" data-toggle="tab">Information</a></li>
    <li><a href="#tab2" data-toggle="tab">Groups</a></li>
	{% comment %}
	Backend for permissions not yet implemented
	<li><a href="#tab3" data-toggle="tab">Permissions</a></li>
	{% endcomment %}
  </ul>
  <div class="tab-content">
    <div class="tab-pane active" id="tab1">
    	{% if edit_user.is_local or not edit_user %}
			{% if required_fields %}
				<div class="alert">
					 Please fill in the required fields(*)
				</div>
			{% endif %}
			{% if username_unavailable %}
				<div class="alert">
					 The username is unavailable
				</div>
			{% endif %}
			<div class="control-group">
				<label class="control-label" for="inputUsername">Username</label>
				<div class="controls">
					<input type="text" id="inputUsername" name="inputUsername" {% if edit_user %}value="{{edit_user.external_identifier}}" disabled {% endif %} placeholder="Username">*
				</div>
			</div>
			<div class="control-group">
				<label class="control-label" for="inputFirstname">First name</label>
				<div class="controls">
					<input type="text" id="inputFirstname" name="inputFirstname" {% if edit_user %}value="{{edit_user.first_name}}" {% endif %} placeholder="Firstname">*
				</div>
			</div>
			<div class="control-group">
				<label class="control-label" for="inputLastname">Last name</label>
				<div class="controls">
					<input type="text" id="inputLastname" name="inputLastname" {% if edit_user %}value="{{edit_user.last_name}}" {% endif %}  placeholder="Lastname">*
				</div>
			</div>
			<div class="control-group">
				<label class="control-label" for="inputEmail">Email</label>
				<div class="controls">
					<input type="text" id="inputEmail" name="inputEmail" {% if edit_user %}value="{{edit_user.email}}" {% endif %}  placeholder="Email">
				</div>
			</div>
			{% if password_diff %}
				<div class="alert">
					 The passwords doesn't match
				</div>
			{% endif %}
			<div class="control-group">
				<label class="control-label" for="inputPassword">Password</label>
				<div class="controls">
					<input type="password" id="inputPassword" name="inputPassword" placeholder="Password">*
				</div>
			</div>
			<div class="control-group">
				<label class="control-label" for="inputPassword2">Password again</label>
				<div class="controls">
					<input type="password" id="inputPassword2" name="inputPassword2" placeholder="Password again">*
				</div>
			</div>
			Required fields(*)
		{% else %}
			<div class="control-group">
				<label class="control-label" for="inputFirstname">First name</label>
				<div class="controls">
					<input type="text" id="inputFirstname" name="inputFirstname" value="{{edit_user.first_name}}" disabled>
				</div>
			</div>
			<div class="control-group">
				<label class="control-label" for="inputLastname">Last name</label>
				<div class="controls">
					<input type="text" id="inputLastname" name="inputLastname" value="{{edit_user.last_name}}" disabled>
				</div>
			</div>
			<div class="control-group">
				<label class="control-label" for="inputEmail">Email</label>
				<div class="controls">
					<input type="text" id="inputEmail" name="inputEmail" value="{{edit_user.email}}" disabled>
				</div>
			</div>
		{% endif %}
			<div class="control-group">
				<div class="controls">
					<label class="checkbox">
						<input type="checkbox" name="inputStaff" {% if edit_user.is_staff %} checked {% endif %} > Is staff
					</label>
					{% comment %}
					<label class="checkbox">
						<input type="checkbox" name="inputSuper" {% if edit_user.is_superuser %} checked {% endif %}> Is superuser
					</label>
					{% endcomment %}
				</div>
			</div>
    </div>
    <div class="tab-pane" id="tab2">
		<div class="control-group">
			<table class="table table-condensed table-bordered table-striped">
				<thead><th>Group</td><th>In</th></thead>
				{% if edit_user %}
					{% user_group_boxes edit_user %}
				{% else %}
					{% group_boxes %}
				{% endif %}
			</table>
			</div>
    </div>
	{% comment %}
	<div class="tab-pane" id="tab3">
		<div class="control-group">	
				<table class="table table-condensed table-bordered table-striped">
				<thead><th>Permission</td><th>Has</th></thead>
				{% if edit_user %}
					{% user_permission_boxes edit_user %}
				{% else %}
					{% permission_boxes %}
				{% endif %}
				</table>			
		</div>
    </div>
    {% endcomment %}
  </div>
</div>                     


<div class="control-group">
	<div class="controls">
		<button type="submit" class="btn btn-large btn-primary">
		{% if edit_user %}
			Save changes
		{% else %}
			Create user
		{% endif %}
		</button>
	</div>
</div>
</form>


{% endblock %}

{% block scripts %}

{% endblock %}